package com.nbot.server.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nbot.server.domain.ChecklogProDO;
import com.nbot.server.service.ChecklogProService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import com.nbot.server.annotation.Log;

/**
 * 
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-08-15 16:37:50
 */

@Controller
@RequestMapping("/server/checklogPro")
public class ChecklogProController {
    @Autowired
    private ChecklogProService checklogProService;

    @GetMapping()
    @RequiresPermissions("server:checklogPro:checklogPro")
    String ChecklogPro() {
        return "server/checklogPro/checklogPro" ;
    }

    @ResponseBody
    @Log("查看")
    @GetMapping("/list")
    @RequiresPermissions("server:checklogPro:checklogPro")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<ChecklogProDO> checklogProList = checklogProService.list(query);
        int total = checklogProService.count(query);
        PageUtils pageUtils = new PageUtils(checklogProList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:checklogPro:add")
    String add() {
        return "server/checklogPro/add" ;
    }

    @GetMapping("/edit/{checkatid}")
    @RequiresPermissions("server:checklogPro:edit")
    String edit(@PathVariable("checkatid") Long checkatid, Model model) {
            ChecklogProDO checklogPro = checklogProService.get(checkatid);
        model.addAttribute("checklogPro" , checklogPro);
        return "server/checklogPro/edit" ;
    }

    /**
     * 保存
     */
    @Log("保存")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:checklogPro:add")
    public R save(ChecklogProDO checklogPro) {
        if (checklogProService.save(checklogPro) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:checklogPro:edit")
    public R update(ChecklogProDO checklogPro) {
            checklogProService.update(checklogPro);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:checklogPro:remove")
    public R remove( Long checkatid) {
        if (checklogProService.remove(checkatid) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:checklogPro:batchRemove")
    public R remove(@RequestParam("ids[]") Long[]checkatids) {
            checklogProService.batchRemove(checkatids);
        return R.ok();
    }

}
